package problem10_09;

//面试题10.09.排序矩阵查找
//https://leetcode.cn/problems/sorted-matrix-search-lcci/

class Solution {
    public boolean searchMatrix(int[][] matrix, int target) {
        int n = matrix.length;
        if(n == 0)  return false;
        int m = matrix[0].length;
        if(m == 0) return false;
        int x = 0, y = m-1;
        while(x < n && y >= 0) {
            if(matrix[x][y] < target) {
                x++;
            }else if(matrix[x][y] > target){
                y--;
            }else if(matrix[x][y] == target) {
                return true;
            }
        }
        return false;
    }
}

/**

[1, 2, 3, 4 ,5],
[6, 7, 8, 9, 10],
[11,12,13,14,15],
[16,17,18,19,20],
[21,22,23,24,25]

 */